<?php

/**
 * Description of dcpdf
 *
 * @author Life Hazard
 */

// Library TCPDF

require_once(APPPATH.'third_party/tcpdf/tcpdf.php');

class dcpdf extends TCPDF {

    var $show_footer = false;
    var $struk_gaji = false;
    
    public function __construct($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8', $diskcache=false, $pdfa=false) {
        parent::__construct($orientation, $unit, $format, $unicode, $encoding, $diskcache, $pdfa);
    }

    public function setFooterVisible($able = false) {
        $this->show_footer = $able;
    }
    
    public function setStrukGaji(){
        $this->struk_gaji = true;    
    }

    public function Header() {
        if($this->show_footer) {
            // Logo
            $image_file = 'images/tcpdf_logo.png'; // *** Very IMP: make sure this image is available on given path on your server
            $this->Image($image_file,15,6,25,20); // x-y-width-high
            
            if ($this->struk_gaji == true){
                $image_file = 'images/tcpdf_logo_2.png'; // *** Very IMP: make sure this image is available on given path on your server
                $this->Image($image_file,170,6,25,20); // x-y-width-high
            }

            $this->Ln(8);
            $this->setX(45);
            $this->SetFont('times', 'C', 19);
            $this->setColor('text',255,0,0);
            
            if ($this->struk_gaji == true){
                $this->Cell(0, 0, '               ANUGERAH GROUPS', 0, false, 'L', 0, '', 0, false, 'M', 'M');
            } else {
                $this->Cell(0, 0, 'PT. ANUGERAH SETIA PERKASA', 0, false, 'L', 0, '', 0, false, 'M', 'M');
            }

            $this->Ln(7);
            $this->setX(45);
            $this->SetFont('times', 'B', 9);
            $this->setColor('text',0,0,0);
            
            if ($this->struk_gaji == false){                            
                $this->Cell(0, 0, 'SHIP OWNER - AGENCY - CHARTERING', 0, false, 'L', 0, '', 0, false, 'M', 'M');
            } else {
                $this->Cell(0, 0, '                                 (SHIP OWNER - AGENCY - CHARTERING)', 0, false, 'L', 0, '', 0, false, 'M', 'M');
            }

            //set style for cell border
            $this->Ln(6);
            $line_width = (0.85 / $this->k);
            $this->SetLineStyle(array('width' => $line_width, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $this->footer_line_color));
            $w_page = isset($this->l['w_page']) ? $this->l['w_page'].' ' : '';
            $this->SetX($this->original_lMargin);
            $this->Cell(0, 0, $w_page, 'T', 0, 'R');
        }

    }

    public function Footer() {
        if($this->show_footer && ($this->struk_gaji == false)) {
            $this->SetY(-25);

            $this->SetTextColorArray($this->footer_text_color);
            //set style for cell border
            $line_width = (0.1 / $this->k);
            $this->SetLineStyle(array('width' => $line_width, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $this->footer_line_color));
            $w_page = isset($this->l['w_page']) ? $this->l['w_page'].' ' : '';

            //Print page number
            $this->SetX($this->original_lMargin);
            $this->Cell(0, 0, $w_page, 'T', 0, 'R');
            $this->Ln(0.5);
            $this->SetFont('courier', 'U', 3);
            $this->SetX($this->original_lMargin);
            $i = 0;
            while($i <= 94) {
                if ($i == 94) {
                    $adl .= "AD";
                } else {
                    $adl .= "ASP";
                }
                $i++;
            }
            $this->Cell(0, 0, $adl, 0, false, 'L', 0, '', 0, false, 'M', 'M');


            
            // drag ttf font ke http://fonts.snm-portal.com/, lalu masukkan ke folder third_party/tcpdf/fonts
            $this->SetFont('times', '', 6);
            $this->Ln();
            $this->Cell(0, 0, 'Head Office: Jl. Laksamana Bintan, Komp. Tanah Mas Blok E/3, Sei Panas - BATAM', 0, 0, 'C');
            $this->Ln();
            $this->Cell(0, 0, 'Ruko Graha Mas Blok A No. 9 - 10 (2nd Floor), Batam Center - BATAM 29461', 0, false, 'C', 0, '', 0, false, 'T', 'M');
            $this->Ln();
            $this->Cell(0, 0, 'Phone : +62 778 472325, Fax : +62 778 472314', 0, false, 'C', 0, '', 0, false, 'T', 'M');
            $this->Ln();
            $this->Cell(0, 0, 'Branch Office : Delta Puspa 82, Delta Sari Indah, Surabaya 61256', 0, false, 'C', 0, '', 0, false, 'T', 'M');
            $this->Ln();
            $this->Cell(0, 0, 'Phone: +62 31 8547163, 8534958, Fax: +62 31 8554756', 0, false, 'C', 0, '', 0, false, 'T', 'M');
            $this->Ln();
            $this->Cell(0, 0, 'Email : marketing@adlestari.com', 0, false, 'C', 0, '', 0, false, 'T', 'M');
            
            // ini buat generate halamana
//            $this->Cell(0, 0, $this->getAliasRightShift().$this->getAliasNumPage().' / '.$this->getAliasNbPages(), 'T', 0, 'R');
        }
    }

}

?>
